package com.tinem.platform.service.task.job.day;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.Date;
import java.util.List;

@Slf4j
@Data
@Component
@Configurable
@ConfigurationProperties(prefix = "job.day.elasticsearch.backups")
public class ElasticsearchBackups {

    List<Config> configs;

    @Scheduled(cron = "0 0 2 * * ?")
    public void execute(){
        Date day = new Date();
        if(CollUtil.isEmpty(configs)){
            return;
        }
        configs.forEach(config -> {
            try {

            }catch (Exception e){
                log.error(JSONObject.toJSONString(config),e);
            }
        });
    }

    public static void main(String[] args) {

    }

    @Data
    public static class Config{
        Duration interval;

        String targetElasticsearchUrl;
        String format;
    }
}
